package com.dkd.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.dkd.system.domain.vo.TbRegionDetailVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.system.domain.TbRegion;
import com.dkd.system.service.ITbRegionService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 区域Controller
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/system/region")
public class TbRegionController extends BaseController
{
    @Resource
    private ITbRegionService tbRegionService;

    /**
     * 查询区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbRegion tbRegion)
    {
        startPage();
        List<TbRegion> list = tbRegionService.selectTbRegionList(tbRegion);
        return getDataTable(list);
    }

    /**
     * 导出区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:export')")
    @Log(title = "区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbRegion tbRegion)
    {
        List<TbRegion> list = tbRegionService.selectTbRegionList(tbRegion);
        ExcelUtil<TbRegion> util = new ExcelUtil<TbRegion>(TbRegion.class);
        util.exportExcel(response, list, "区域数据");
    }

    /**
     * 获取区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:region:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbRegionService.selectTbRegionById(id));
    }

    @PreAuthorize("@ss.hasPermi('system:region:query')")
    @GetMapping(value = "/getinfo/{id}")
    public AjaxResult getInfosb(@PathVariable("id") Long id)
    {
       TbRegionDetailVo tbRegionDetailVo= tbRegionService.selectTbRegionById1(id);
        return success(tbRegionDetailVo);
    }

    /**
     * 新增区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:add')")
    @Log(title = "区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRegion tbRegion)
    {
        return toAjax(tbRegionService.insertTbRegion(tbRegion));
    }

    /**
     * 修改区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRegion tbRegion)
    {
        return toAjax(tbRegionService.updateTbRegion(tbRegion));
    }

    /**
     * 删除区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:remove')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbRegionService.deleteTbRegionByIds(ids));
    }
}
